package com.dbh.company.freeform.saas;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author dongbanghui
 * @create 2023/6/30
 */
public class SaasDataExport {

    public static void main(String[] args) {
        revokeContract();

    }

    private static void exportContractFile() {
        String url = "http://freeform.lianjia.com/contractSaas/getContractDetail";

        List<String> list = new ArrayList<>();
        FileUtil.readLines("D:\\data\\softData\\a.txt", CharsetUtil.CHARSET_UTF_8, list);

        list.forEach(item -> {
            HashMap<String, String> body = new HashMap<>();
            body.put("instanceId", item);
            String result = HttpRequest.post(url)
                    .header("loginToken", "2.0111a9beb284385a9f0001cb545939e71c71eaa02b")
                    .contentType("application/json;charset=UTF-8")
                    .body(JSONUtil.toJsonStr(body))
                    .timeout(1000)
                    .execute().body();
            JSONObject jsonObject = JSONUtil.parseObj(result);
            Object data = jsonObject.get("result");
            JSONObject jsonObject2 = JSONUtil.parseObj(data);
            Object download = jsonObject2.get("download");
            if (download != null) {
                String link = StrUtil.toString(JSONUtil.parseObj(download).get("link"));
                HttpUtil.downloadFile(link, "D:\\data\\softData\\temp\\" + item + ".pdf");
            }
        });
    }

    private static void revokeContract() {
        String url = "http://freeform.lianjia.com/contractSaas/contractRevoke";

        List<String> list = new ArrayList<>();
        FileUtil.readLines("D:\\tmp\\b.txt", CharsetUtil.CHARSET_UTF_8, list);

        list.forEach(item -> {
            HashMap<String, String> body = new HashMap<>();
            body.put("application", "bjlj_humanResourceCenter");
            body.put("instanceId", item);
            String result = HttpRequest.post(url)
                    .header("loginToken", "2.0111a9beb284385a9f0001cb54b30ad5ed200a5e6e")
                    .contentType("application/json;charset=UTF-8")
                    .body(JSONUtil.toJsonStr(body))
                    .timeout(1000)
                    .execute().body();
            Console.log("已作废合同为-->{}", result);
        });
    }
}
